package cn.blb.service.edu.controller;


import cn.blb.common.result.Result;
import cn.blb.service.edu.entity.Video;
import cn.blb.service.edu.service.VideoService;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 课程视频 前端控制器
 * </p>
 *
 * @author ccl
 * @since 2022-03-17
 */
@CrossOrigin
@RestController
@RequestMapping("/edu/video")
public class VideoController {

    private final VideoService videoService;

    public VideoController(VideoService videoService) {
        this.videoService = videoService;
    }

    @PostMapping("saveVideo")
    public Result save(@RequestBody Video video){

        return videoService.saveVideo(video)?Result.ok():Result.error();
    }

    @PostMapping("{id}")
    public Result getVideoById(@PathVariable String id){
        Video video = videoService.getById(id);
        return Result.ok().setData("item",video);
    }

    @PostMapping("updateVideoById")
    public Result updateVideoById(@RequestBody Video video){
        return videoService.updateById(video)?Result.ok():Result.error();
    }

    @DeleteMapping("{id}")
    public Result delVideoById(@PathVariable String id){
        return videoService.removeById(id) ? Result.ok():Result.error();
    }


}

